package com.travel.config;

/**
 * @author: libin
 * Date: 2025/6/10 8:48
 * Description:
 **/
//import com.travel.interceptor.MemberLoginInterceptor
import com.travel.interceptor.MemberLoginInterceptor1;
import com.travel.properties.UserAuthProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Component
public class WebMvcConfiguration implements WebMvcConfigurer {

//    @Autowired
//    private MemberLoginInterceptor memberLoginInterceptor;

    @Autowired
    private MemberLoginInterceptor1 memberLoginInterceptor;


    @Autowired
    private UserAuthProperties userAuthProperties;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(memberLoginInterceptor)
                .excludePathPatterns(userAuthProperties.getNoAuthUrls())
                .addPathPatterns("/**");
    }
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowCredentials(true)  // 是否允许在跨域的情况下传递Cookie
                .allowedMethods("*")  // 允许的请求方式
                .allowedHeaders("*")  // 允许所以请求头
                .allowedOriginPatterns("*"); // 允许请求来源的域规则
    }


}

